<?PHP echo('<?xml version="1.0" encoding="utf-8" ?>');?>
<?PHP
include '../admin/m/base/mod_display.php';
include '../admin/m/base/mod_sql.php';
include '../admin/m/base/m_paginator.php';
include '../admin/m/content/m_content.php';
include '../admin/m/content/m_content_category.php';

include '../admin/m/ads/m_ads.php';
include '../admin/m/music/m_music.php';
include '../admin/m/config.php';

#change this

global $conf;
$conf->debug=false;
session_start();
if(!empty($_POST['xmlURL']))
{
	$url=$_POST['xmlURL'];
}
else if(!empty($_GET['xmlURL']))
{
	$url=$_GET['xmlURL'];
}

$q = str_replace($conf->absolute_path, "", $url);
$qm = explode("/",$q);


$c_content=new content;
$view=false;
if(!empty($qm[1]) && $qm[0]=='content')
{
	$c_content->where['id']=$qm[1];
	$c_content->get_content();
	//$c_content->get_content_addons();
	$content=$c_content->piece;
	$view=true;
}
else if(!empty($qm[1]) && $qm[0]=='play')
{

	$c_content->where['id']=$qm[1];
	$c_content->get_content();
	$c_content->get_content_extras();
	$content=$c_content->piece;

	$cat=$content['category'];
	$view=true;
}
else if(empty($qm[1]) && $qm[0]=='play')
{

	$c_content->where['status']='enabled';
	$c_content->where['type']='video';
	$c_content->input['LIMITDATE']='true';
	$c_content->options['order'][0]='start';
	$c_content->options['order'][1]='desc';
	$c_content->get_content();
	$c_content->get_content_extras();
	$content=$c_content->piece;

	$cat=$content['category'];
	
	$view=true;
}
else if(!empty($qm[1]) && $qm[0]=='community')
{
	$c_content->where['category']=$qm[1];
	$c_content->get_content();
//	$c_content->get_content_addons();
	$content=$c_content->piece;
	$view=true;
}
else if(!empty($_POST))
{
	$conf->set_default_q();
	$c_content->where['id']=$conf->qm[1];
	$c_content->get_content();
//c_content->get_content_addons();
	$content=$c_content->piece;
	

	$view=true;
}
if(!$conf->advertise)
{
	$view=true;
}
//	$view=true;	
if($view)
{

//get playlist
 mp($content['playlist']);
	$music = new music();
	$music->post['id']=$content['playlist'];
	$playlist=$music->get_songs_for_playlist();
	
	$aad = new ads();
	$aad->zone=1;
	$aad->category=$cat;
	$ad_music=$aad->ad_chooser();
	
	$vad = new ads();
	$vad->zone=2;
	$vad->category=$cat;
	$ad_video=$vad->ad_chooser();
	
	$iad = new ads();
	$iad->zone=3;
	$iad->category=$cat;
	$ad_image=$iad->ad_chooser();
	
} 

else
{
	
}
?>

<!--sequence>
  <stinger /> 
  <audio_ad /> 
  <video_ad /> 
  <song /> 
  <song /> 
  <song /> 
  <audio_ad /> 
  <video_ad /> 
  <loop /> 
  <song /> 
  <song /> 
  <song /> 
  <audio_ad /> 
</sequence>-->


<playlist>
	<enable_video_ads><![CDATA[1]]></enable_video_ads>
	<enable_audio_ads><![CDATA[1]]></enable_audio_ads>
	<audio_ad_interval><![CDATA[3]]></audio_ad_interval>
	
	<controls>
		<play_pause><![CDATA[1]]></play_pause>
		<next><![CDATA[1]]></next>
		<seek><![CDATA[0]]></seek>
		<fullscreen><![CDATA[1]]></fullscreen>
		<twitter><![CDATA[1]]></twitter>
		<facebook><![CDATA[1]]></facebook>
		<buy><![CDATA[1]]></buy>
	</controls>

	
	<content><?PHP echo $content['id'];?></content>
	<xmlurl><?PHP echo $url;?></xmlurl>
	<video_ads>
		<?PHP
		
		foreach($ad_video as $x)
		{
			?>
					<ad>
						<server><?PHP echo $x['server'];?></server>
						<path><?PHP echo $x['file'];?></path>
						<redirect_url><![CDATA[<?PHP echo $x['link'];?>]]></redirect_url>
						<campaign><?PHP echo $x['campaign'];?></campaign>
						<ad_media><?PHP echo $x['id'];?></ad_media>
						<zone><?PHP echo $x['zone'];?></zone>
					</ad>
			<?PHP
		}
		?>
	</video_ads>
	<image_ads>
	<?PHP
	
			foreach($ad_image as $x)
			{
		

				?>
		
			
					
						<ad>
							<campaign><?PHP echo $x['campaign'];?></campaign>
							<ad_media><?PHP echo $x['id'];?></ad_media>
							<zone><?PHP echo $x['zone'];?></zone>
							<redirect_url><![CDATA[<?PHP echo $x['link'];?>]]></redirect_url>
							<path><?PHP echo ap($x['image']);?></path>
						</ad>
				<?PHP
				
				$image=ap($x['image']);
			}
	?>
		
	</image_ads>
	<audio_ads>
	
		<?PHP
		
		foreach($ad_music as $x)
		{
			
	
			?>
			
				
					<ad>
						<server><?PHP echo $x['server'];?></server>
						<path><?PHP echo $x['file'];?></path>
						<campaign><?PHP echo $x['campaign'];?></campaign>
						<ad_media><?PHP echo $x['id'];?></ad_media>
						<zone><?PHP echo $x['zone'];?></zone>
						<image_path><?PHP echo $image;?></image_path>
						<image_redirect_url><![CDATA[<?PHP echo $x['link'];?>]]></image_redirect_url>
					</ad>
			<?PHP
		}
		?>
	

	</audio_ads>
	

	
	<tracks>
		
		<?PHP
		
		foreach($playlist as $x)
		{
	
					$duration = 0;
					$split = explode(':', $x['duration']);
					if(isset($split[0]) && is_numeric($split[0])) $duration +=  $split[0] * 60;
					if(isset($split[1]) && is_numeric($split[1])) $duration +=  $split[1];
				?>
				<track>
					<has_video><![CDATA[0]]></has_video> 
					<type>media</type>
					<content_id><?PHP echo $content['id'];?></content_id>
					<media><?PHP echo $x['id']?></media>
					<media_id><?PHP echo $x['id']?></media_id>
					<duration><?php echo $duration;?></duration>
					<server><?PHP echo $x['server'];?></server>
					<path><?PHP echo $x['file']?></path>
					<title><?PHP echo $x['name']?></title>
					<artist><?PHP echo $x['artist']?></artist>
					<album><?PHP echo $x['album']?></album>
					
					<record_producer><?PHP echo $x['label']?></record_producer>
					<image_path><?PHP echo $x['image_url']?></image_path>
					<image_redirect_url><![CDATA[<?PHP echo $x['link'];?>]]></image_redirect_url>
					
				</track>
			<?PHP
		}
		?>
	
		
	
	</tracks>
	
</playlist>